
const tagColor = (el, binding) => {
	// 判断是否为el-tag
	if(el.classList.contains('el-tag')) {
		let value = binding.value;
		// 必须使用16进制
		if(value[0] != '#') {
			return;
		}
		el.style.color = value;
		el.style.backgroundColor = hexToRgba(value, 0.1);
		el.style.borderColor = hexToRgba(value, 0.2);
	}
}

// 16进制转换rgba
function hexToRgba(hex, opacity) {
	// 去除#号
  var color = hex.replace("#", "");
  // 分割成红、绿、蓝三部分
  var red = parseInt(color.substring(0,2), 16);
  var green = parseInt(color.substring(2,4), 16);
  var blue = parseInt(color.substring(4,6), 16);
  return `rgb(${red}, ${green}, ${blue}, ${opacity})`;
}

export default tagColor;